package com.wxapp.sale.api.enums.order;

import com.wxapp.common.constant.base.IBaseEnum;
import com.wxapp.common.util.check.CheckUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lgl
 */
public enum OrderStateEnum implements IBaseEnum<String> {
    UNPAID("unpaid", "未支付"),
    PAID("paid", "已付款"),
    UNSHIPPED("unshipped", "未发货"),
    SHIPPED("shipped", "已发货"),
    UNSIGNED("unsigned", "未签收"),
    SIGN("sign", "已签收"),
    REFUSAL("refusal", "拒收"),
    FAIL("fail", "支付失败"),
    EXPIRE("expire", "已过期"),
    COMPLETED("completed", "已完成");
    private final String value;
    private final String desc;

    OrderStateEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    @Override
    public String getValue() {
        return this.value;
    }

    @Override
    public String getDesc() {
        return this.desc;
    }

    /**
     * 得到下一状态
     */
    public static List<OrderStateEnum> getNext(OrderStateEnum type) {
        if (CheckUtil.isNullEnum(type)) {
            return new ArrayList<>();
        }
        List<OrderStateEnum> nextList = new ArrayList<>();
        switch (type) {
            case UNPAID:
                nextList.add(PAID);
                nextList.add(EXPIRE);
                nextList.add(FAIL);
                break;
            case PAID:
                nextList.add(UNSHIPPED);
                break;
            case UNSHIPPED:
                nextList.add(SHIPPED);
                break;
            case SHIPPED:
                nextList.add(UNSIGNED);
                break;
            case UNSIGNED:
                nextList.add(SIGN);
                nextList.add(REFUSAL);
                break;
            default:
                nextList.add(COMPLETED);
                break;
        }
        return nextList;
    }

    /**
     * 转换是否是下一状态
     */
    public static boolean isNextState(OrderStateEnum previousState, OrderStateEnum nextState) {
        if (CheckUtil.isNullEnum(previousState) || CheckUtil.isNullEnum(nextState)) {
            return false;
        }
        var next = getNext(previousState);
        return next.contains(nextState);
    }
}
